#include "gfxTowerBeamFireFX.h"
//#ifdef USE_SOUND_SYSTEM
   #include "soundsystem.h"
//#endif

#include <QBrush>
#include <QSound>
#include <QDebug>

GFXTowerBeamFireFX::GFXTowerBeamFireFX(ClientEntity *entity, QGraphicsItem *parent)
   : GFXItem(entity, parent)
{
   if (mEntity && mEntity->target)
   {
      QVector2D diff =  mEntity->target->pos - mEntity->pos;
      mEnd = diff.toPointF();
      mStart = (diff.normalized()*8).toPointF(); //offset from center
   }
   //QSound::play("./res/sfx/beamfire.wav");
//#ifdef USE_SOUND_SYSTEM
   SoundSystem::instance()->playSound(SoundSystem::SFX_TOWER_BEAM_FIRE);
//#endif
}

GFXTowerBeamFireFX::~GFXTowerBeamFireFX()
{
}

QRectF GFXTowerBeamFireFX::boundingRect() const
{
   return QRectF();
}


void GFXTowerBeamFireFX::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
   painter->setPen(QPen(QBrush(mEntity->base.color), mTicksAlive%6));
   painter->drawLine(mStart, mEnd);
}

void GFXTowerBeamFireFX::tick()
{
   if (mCreateTime.msecsTo(QTime::currentTime()) >= 200)
      mActive = false;
   mTicksAlive++;
}
